<template>
  <home-pannel title="人气推荐" subTitle='人气爆款 不容错过' ref="target">
        <template #main>
          <ul ref="pannel" class="goods-list" >
              <li v-for="item in goodsList" :key="item.id">
                <RouterLink to="/">
                  <img  v-lazyload='item.picture' alt="" />
                  <p class="title">{{ item.title }}</p>
                  <p class="desc">{{ item.alt }}</p>
                </RouterLink>
              </li>
        </ul>
        </template>
      </home-pannel>
</template>

<script>
import HomePannel from './home-pannel.vue'
import { ref } from 'vue'
import { findHot } from '@/api/home'
import { useObserver } from '@/compositions/useObserver'
export default {
  name: 'HomeHot',
  components: {
    HomePannel
  },
  props: {
    // 主标题
    title: {
      type: String,
      default: ''
    },
    // 副标题
    subTitle: {
      type: String,
      default: ''
    }
  },
  setup () {
    const goodsList = ref([])
    // 获取热门推荐
    async function loadGoodsList () {
      const res = await findHot()
      // console.log(res)
      goodsList.value = res.result
    }
    // onMounted(() => {
    //   loadGoodsList()
    // })
    const { target } = useObserver(loadGoodsList)

    return {
      goodsList,
      target
    }
  }
}
</script>
<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
